<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>王者助手-兵线刷新时间计时器</title>
    <meta name=keywords content="王者荣耀,王者助手,兵线计时器,兵线助手">
    <meta name=description content="王者荣耀兵线刷新时间计时器，帮助你准确把握兵线刷新时机。">

    <style type="text/css">
        #inputDiv {
            height: 80px;
            margin: 0 auto;
            text-align: center;
        }

        #inputDiv ul {
            display: inline-block;
            list-style: none;
        }

        #inputDiv li {
            display: inline;
            float:left;
            text-align: center;
        }

        #inputDiv input {
            width: 120px;
            height:80px;
            text-align: center;
            font-size: 30px;
        }

        #inputDiv span {
            width: 20px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            font-size: 30px;
            display: inline-block;
        }

        #curTime{
            font-size: 35px;
        }

        #lastTime{
            font-size: 50px;
        }

        #rootDiv div{
            margin-top: 30px;
        }

        button{
            text-align: center;
            width: 120px;
            height: 60px;
        }
    </style>

    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?bafaf39a90c515d321024474cf3db2bf";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</head>
<body>
<div style="width: 80%; margin: 0 auto;text-align: center;" id="rootDiv">
    <div>
        <span style="display: inline-block;margin-top: 30px;">请输入当前游戏时间(默认是首波兵线时间开局10秒)，然后点击下方按钮</span>
    </div>
    <div id="inputDiv">
        <ul>
            <li><input type="text" id="minute1" onkeyup="value=value.replace(/[^\d]/g,'')" value="0" onkeypress="onEnterPress();"/></li>
            <li><input type="text" id="minute2" onkeyup="value=value.replace(/[^\d]/g,'')" value="0" onkeypress="onEnterPress();"/></li>
            <li><span>:</span></li>
            <li><input type="text" id="seconds1" onkeyup="value=value.replace(/[^\d]/g,'')" value="1" onkeypress="onEnterPress();"/></li>
            <li><input type="text" id="seconds2" onkeyup="value=value.replace(/[^\d]/g,'')" value="0" onkeypress="onEnterPress();"/></li>
        </ul>
    </div>
    <div>
        <button id="timeIncrease" type="button" onclick="timeIncrease()">时间加1</button>
        <button id="timeGoBtn" type="button" onclick="timeGo()">开始计时</button>
        <button id="timeDecrease" type="button" onclick="timeDecrease()">时间减1</button>
    </div>
    <div>
        <span>当前游戏时间</span>
    </div>
    <div>
        <span id="curTime">00:00</span>
    </div>
    <div>
        <span>最近兵线倒计时</span>
        <br/>
        <span style="font-size: small;">(随着时间的缩短，颜色依次为粉色、黄色、红色)</span>
    </div>
    <div>
        <span id="lastTime">00:00</span>
    </div>
</div>
<script>
    var curTime = 0;
    var handler;
    var lastIndex=0;
    //分钟秒
    var minuteTimeArray=[];
    //换算成秒
    var secondTimeArray=[10,43,77,110,143,176,209,242,276,309,342,375,409,442,475,508,542,575,608,641,675,708,741,774,808,841,874,907,941,974,1007,1040,1074,1107,1140,1173,1207,1240,1273,1306,1339,1373,1406,1439,1473,1505,1538,1571,1605,1638,1670,1704,1737,1770,1804];
    var lastTimeSpan,curTimeSpan;

    function onEnterPress() {
        if (event.keyCode === 13) {
            timeGo();
        }
    }

    function timeIncrease() {
        curTime++;

        refreshTimeShow()
    }

    function timeDecrease() {
        curTime--;

        if(curTime<0){
            curTime=0;
        }

        refreshTimeShow();
    }

    function timeGo() {
        if(handler!==undefined) {
            clearInterval(handler);
        }
        curTime=0;
        document.getElementById("timeGoBtn").innerText="重新计时";

        var minute1=document.getElementById("minute1").value;
        var minute2=document.getElementById("minute2").value;
        var seconds1=document.getElementById("seconds1").value;
        var seconds2=document.getElementById("seconds2").value;

        curTime=parseInt(minute1===''?0:minute1)*10*60
            +parseInt(minute2===''?0:minute2)*60
            +parseInt(seconds1===''?0:seconds1)*10
            +parseInt(seconds2===''?0:seconds2);

        curTimeSpan=document.getElementById("curTime");
        lastTimeSpan=document.getElementById("lastTime");

        refreshTimeShow();

        handler=setInterval(timeRepeat,1000);
    }

    function timeRepeat() {
        curTime++;

        refreshTimeShow()
    }

    function refreshTimeShow() {
        for (let i = 0; i <secondTimeArray.length; i++) {
            if(secondTimeArray[i]>curTime){
                lastIndex=i;
                break;
            }
        }

        var minute=parseInt(curTime/60);
        var seconds=curTime%60;

        var lastTime=secondTimeArray[lastIndex]-curTime;
        var lastMinute=parseInt(lastTime/60);
        var lastSeconds=lastTime%60;

        curTimeSpan.innerText=(minute<10?"0"+minute:minute)
            +":"
            +(seconds<10?"0"+seconds:seconds);

        lastTimeSpan.innerText=(lastMinute<10?"0"+lastMinute:lastMinute)
            +":"
            +(lastSeconds<10?"0"+lastSeconds:lastSeconds);

        if(lastTime>30) {
            lastTimeSpan.style.color="black";
            lastTimeSpan.style.backgroundColor="transparent";
        }else if(lastTime>20) {
            lastTimeSpan.style.color="white";
            lastTimeSpan.style.backgroundColor="#FF00FF";
        }else if(lastTime>10){
            lastTimeSpan.style.color="gray";
            lastTimeSpan.style.backgroundColor="yellow";
        }else{
            lastTimeSpan.style.color="white";
            lastTimeSpan.style.backgroundColor="red";
        }
    }
</script>
</body>
</html>